<?php

namespace app\commons\model;

use think\Model;
use think\model\concern\SoftDelete;

class UserCard extends Model
{
    use SoftDelete;

    protected $deleteTime = 'delete_time';
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    public $autoWriteTimestamp = true;


    /**
     * 格式化优惠券开始时间
     * @param $value
     * @return false|string
     */
    public function getStartTimeAttr($value){
        return date('Y-m-d',strtotime($value));
    }

    /**
     * 创建时间
     * @param $value
     * @return false|string
     */
    public function getCreatetimeAttr($value){
        return date('Y-m-d',$value);
    }


    /**
     * 格式化优惠券开始时间
     * @param $value
     * @return false|string
     */
    public function getExpireTimeAttr($value){
        return date('Y-m-d',strtotime($value));
    }

    /**
     * 关联用户
     * @return \think\model\relation\HasOne
     */
    public function member(){
        return $this->hasOne(Member::class,'id','user_id')->field(['nickname','avatar','id']);
    }

}